package edu.ccut.saturn.studio.dialog;

import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import edu.ccut.saturn.studio.Activator;
import edu.ccut.saturn.studio.Images;
import edu.ccut.saturn.studio.core.util.eclipse.Messages;
import edu.ccut.saturn.studio.logic.model.Connection;

public class SaturnDecisionConnectionDialog extends TitleAreaDialog {

	private Text text;
	private Connection connectionShape;
	public SaturnDecisionConnectionDialog(Shell parentShell,Connection connectionShape) {
		super(parentShell);
		this.connectionShape = connectionShape;
	}
	
	protected Control createDialogArea(Composite parent) {
		Composite area = (Composite) super.createDialogArea(parent);
		Composite container = new Composite(area, SWT.NONE);
		final GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 2;
		container.setLayout(gridLayout);
		final GridData gd_container = new GridData(SWT.FILL, SWT.CENTER, false, false);
		gd_container.heightHint = 46;
		gd_container.widthHint = 422;
		container.setLayoutData(gd_container);

		final Label label = new Label(container, SWT.NONE);
		label.setText(Messages.getString("SaturnDecisionConnectionDialog.name")); //$NON-NLS-1$

		text = new Text(container, SWT.BORDER);
		text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
		text.setText(this.connectionShape.getLineName().trim());
		setTitleImage(Activator.getImage(Images.SATURN_ICONS_MAXNAME));
		return area;
	}
	
	protected void buttonPressed(int buttonId) {
		if(buttonId==IDialogConstants.OK_ID){
			this.connectionShape.setLineName(text.getText().trim());
		}
		super.buttonPressed(buttonId);
	}
	
	protected Point getInitialSize() {
		return new Point(434, 194);
	}
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setImage(Activator.getImage(Images.SATURN_ICONS_SMALLNAME));
	}
}
